﻿using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {

    [System.NonSerialized]
    public string username;
    public bool isLocalBullet = false;//是否是本机玩家的子弹

	// Use this for initialization
	void Start () {
	
	}

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Tank"))
        {
            Player player = other.GetComponent<Player>();
            string user = player.userData.username;
            if (user != this.username)
            {
                //是本机玩家的子弹才发送网络数据
                if (isLocalBullet)
                {
                    //子弹打中目标，直接发送数据到服务器
                    HitDat data = new HitDat();
                    data.originUsername = username;
                    data.targetUsername = player.userData.username;
                    NetworkManager.Instance.SendMessage(Protocol.PlayerOnHit_CMD, JsonUtility.ToJson(data));
                }
                //不是自己才销毁
                Destroy(gameObject);
            }
        }
        else
        {//不是坦克是地面，销毁
            Destroy(gameObject);
        }
    }
}
